home *** CD-ROM | disk | FTP | other *** search
- ; Listing 3
- ; ctlprc.sub source code
- ; Provided by Absoft Tech Support
- ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;
- ; Title: Toolbox Control/Filter glue procedure.
- ;
- ; Produced by: Absoft Soft, Inc. Date: 8/19/86
- ;
- ; Purpose: To interface MacFortran with the Macintosh's Toolbox.
- ;
- ; Notes: This procedure takes a FORTRAN procedure as an argument and returns
- ; a pointer to a procedure that can be called by the Macintosh
- ; toolbox. This is used to allow control tracking and filter procedures
- ; to be written in FORTRAN.
- ;
- ; Warnings/Limitations: This procedure locks itself into the FORTRAN heap
- ; when it is called for the first time. Since it returns pointers
- ; to locations within itself, it must never move. It should
- ; therefore be called as the first executable
- ; statement in the main program. If it is not desireable to set
- ; up the procedure pointers at the begining of the main program,
- ; ctlprc can also be called with a zero for the procedure argument:
- ;
- ; DUMMY = CTLPRC(0, 0)
- ;
- ; This will lock the subroutine in memory without setting up a
- ; procedure.
- ;
- ; Calling sequence:
- ; <procedure pointer> = CTLPRC(<filter proc>, <argument byte count>)
- ; where
- ; <procedure pointer> is a FORTRAN INTEGER variable. This will
- ; be assigned a pointer to a procedure. This variable
- ; is then used as the filter procedure parameter in calls
- ; to the toolbox.
- ; <filter proc> is the name of the FORTRAN procedure to be called
- ; from the toolbox. This should be a procedure with a single
- ; integer parameter, which on entry will contain a pointer to
- ; the arguments from the toolbox as they appear on the stack.
- ; This must be declared as EXTERNAL in the program unit where
- ; CTLPRC is used; this will usually be the main program.
- ; <argument byte count> is the total number of bytes of arguments that
- ; the toolbox will push on the stack for the type of filter
- ; procedure that this FORTRAN procedure will be used for.
- ; For example, if the procudure is to be used to track a scroll
- ; bar, the toolbox will pass 2 parameters on the stack; the
- ; control handle (4 bytes) and the part code (2 bytes), for
- ; a total of 6 bytes. The track procdure should be initialized
- ; with
- ; INTEGER TRACK
- ; .
- ; .
- ; .
- ; TRACK = CTLPRC(FTRACK, 6)
- ; where FTRACK is the FORTRAN procedure name. The integer
- ; variable TRACK will contain the address of a toolbox callable
- ; procedure. A maximum of 16 procedures can be set up by
- ; ctlprc. When this limit is reached, ctlprc will return
- ; a zero instead of a procedure pointer.
- ;
- ;
- ; Modification History:
- ;
- ; 30 OCT 86 Saved and tested D0 for register based ctl procs. RTC
- ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- INCLUDE TOOLEQU.D
-
- CTLPRC: LEA 4(A7),A4 ; Load the original Stack Pointer...
- LEA CTLPRC(PC),A5 ; Get the execution address.
- CMPA.L A0,A5 ; Test to see if we are loaded in heap
- BMI.S L1 ; If linked avoid the set.
- MOVE.W #1,-8(A1) ; Mark this routine PERMENANT.
- L1: MOVE.L A0,APPLSCRATCH+4 ; Save impure pointer.
- LEA NXTPRC,A2 ; Get address of next routine ptr.
- MOVE.L (A2),D0 ; Get offset to next routine.
- LEA PRCTBL,A1 ; Get pointer to procedure table.
- ADD.L D0,A1 ; Point to next procedure.
- CLR.L D0 ; Flag no room.
- LEA ENDPRC,A3 ; Get address of end of table.
- CMPA.L A3,A2 ; Any room left?
- BGE.S NOROOM ; no
- MOVE.L A1,D0 ; Return procedure pointer.
- MOVE.L (A4)+,A5 ; Get a pointer to the count.
- MOVE.L (A5),D1 ; Get the argument byte count.
- ADDQ.W #2,A1 ; Bypass the BSR.S instruction.
- MOVE.W D1,(A1)+ ; Store the argument byte count.
- MOVE.L (A4)+,A5 ; Get pointer to the proc. ptr.
- MOVE.L (A5)+,(A1)+ ; Store the procedure pointer.
- BNE.S OKPROC ; Not nil - update the offset.
- MOVEQ #0,D0 ; Nil procedure - flag not installed.
- BRA.S NOROOM ; Do not update offset.
- OKPROC: ADDI.L #8,(A2) ; Offset to next procedure.
- NOROOM: RTS
-
-
- NXTPRC: DC.L 0
-
- PRCTBL: BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
-
- BSR.S GLUE
- DC.W 0
- DC.L 0
- ENDPRC:
-
-
- GLUE: MOVE.L A7,A1 ; Save pointer to procedure info.
- MOVEM.L D2-D7/A2-A5,-(A7) ; Save the world.
- MOVE.L APPLSCRATCH+4,A0 ; Restore impure pointer.
- MOVE.L (A0),A4 ; Restore runtime library pointer.
- LINK A6,#-1024 ; Get an arithmetic stack.
- LEA -4(A6),A5 ; Put math stack in A5.
- MOVE.L (A1),A2 ; Get pointer to proc. info.
- MOVE.W (A2)+,-(A7) ; Save the argument byte count.
- MOVE.L (A2),A2 ; Get the procedure address.
- PEA 8(A1) ; Push a pointer to the arguments.
- MOVE.L A7,-(A7) ; Push a pointer to the arg. pointer.
- JSR (A2) ; Call the FORTRAN procedure.
- ADDQ.W #8,A7 ; Push argument to FORTRAN proc.
- MOVE.W (A7)+,D1 ; Get the argument byte count.
- UNLK A6 ; Return aritmetic stack.
- MOVEM.L (A7)+,D2-D7/A2-A5 ; Restore the world.
- ADDQ.W #4,A7 ; Bypass pointer to procedure info.
- MOVE.L (A7)+,A1 ; Save return address.
- ADD.W D1,A7 ; Pop arguments.
- TST.W D0 ; Set the condition codes.
- JMP (A1) ; Return to the toolbox.
-
- END
-
-